package com.jmuok.web.fff.web.vaadin;

import java.util.Locale;

import org.springframework.context.ApplicationContext;
import org.springframework.context.i18n.LocaleContextHolder;

import com.jmuok.web.fff.util.ApplicationHelper;
import com.vaadin.Application;

public abstract class BaseApplication extends Application {

	private static final long serialVersionUID = -6428223455239195008L;
	protected static ApplicationHelper helper = ApplicationHelper.instance();
	protected static CustomizedSystemMessages systemMessages = new CustomizedSystemMessages();

	static {

		systemMessages.setSessionExpiredCaption(helper
				.getMessage("sessionExpiredCaption"));
		systemMessages.setSessionExpiredMessage(helper
				.getMessage("sessionExpiredMessage"));
		systemMessages.setCommunicationErrorCaption(helper
				.getMessage("communicationErrorCaption"));
		systemMessages.setCommunicationErrorMessage(helper
				.getMessage("communicationErrorMessage"));
		systemMessages.setAuthenticationErrorCaption(helper
				.getMessage("authenticationErrorCaption"));
		systemMessages.setAuthenticationErrorMessage(helper
				.getMessage("authenticationErrorMessage"));
		systemMessages.setInternalErrorCaption(helper
				.getMessage("internalErrorCaption"));
		systemMessages.setInternalErrorMessage(helper
				.getMessage("internalErrorMessage"));
		systemMessages.setOutOfSyncCaption(helper
				.getMessage("outOfSyncCaption"));
		systemMessages.setOutOfSyncMessage(helper
				.getMessage("outOfSyncMessage"));
		systemMessages.setCookiesDisabledCaption(helper
				.getMessage("cookiesDisabledCaption"));
		systemMessages.setCookiesDisabledMessage(helper
				.getMessage("cookiesDisabledMessage"));
	}

	@Override
	public Locale getLocale() {
		return LocaleContextHolder.getLocale();
	}

	@Override
	public void setLocale(Locale locale) {
		LocaleContextHolder.setLocale(locale);
	}

	public String getMessage(String key) {
		return helper.getMessage(key);
	}

	public String getMessage(String key, String... args) {
		return helper.getMessage(key, args);
	}

	public ApplicationContext getApplicationContext() {
		return ApplicationHelper.getApplicationContext(this);
	}

	public static SystemMessages getSystemMessages() {

		// String sessionExpiredURL = null;
		// boolean sessionExpiredNotificationEnabled = true;

		// String communicationErrorURL = null;
		// boolean communicationErrorNotificationEnabled = true;

		// String authenticationErrorURL = null;
		// boolean authenticationErrorNotificationEnabled = true;

		// String internalErrorURL = null;
		// boolean internalErrorNotificationEnabled = true;

		// String outOfSyncURL = null;
		// boolean outOfSyncNotificationEnabled = true;
		// String cookiesDisabledURL = null;
		// boolean cookiesDisabledNotificationEnabled = true;

		return systemMessages;

	}

}
